package com.ljyhhh.SmartCity.activity.fragment.brokenLine.chart

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.utils.ColorTemplate
import com.ljyhhh.SmartCity.R
import kotlinx.android.synthetic.main.activity_my_bar_chart.*

class MyBarChart : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_bar_chart)
        val entries = ArrayList<BarEntry>()
        entries.add(BarEntry(0f, 5f))
        entries.add(BarEntry(1f, 7f))
        entries.add(BarEntry(2f, 6f))
        entries.add(BarEntry(3f, 8f))
        entries.add(BarEntry(4f, 7f))
        entries.add(BarEntry(5f, 5f))

        // 创建数据集
        val dataSet = BarDataSet(entries, "柱状图示例")
        dataSet.colors = ColorTemplate.COLORFUL_COLORS.toMutableList()

        // 创建数据对象
        val barData = BarData(dataSet)

        // 设置图表数据
        bar_chart.data = barData

        // 设置图表属性
        bar_chart.invalidate() // 刷新图表
    }
}